home *** CD-ROM | disk | FTP | other *** search
- package com.ms.dxmedia;
-
- import com.ms.awt.HeavyComponent;
- import com.ms.awt.WComponentPeer;
- import com.ms.com.ComException;
- import com.ms.com.ComFailException;
- import com.ms.dxmedia.rawcom.DAView;
- import com.ms.dxmedia.rawcom.IDAPreferences;
- import com.ms.dxmedia.rawcom.IDAView;
- import com.ms.dxmedia.rawcom.IDAViewSite;
- import java.applet.Applet;
- import java.awt.Canvas;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Graphics;
- import java.awt.event.ComponentEvent;
- import java.awt.event.ComponentListener;
- import java.net.MalformedURLException;
- import java.net.URL;
-
- public abstract class DXMCanvasBase extends Canvas implements IDAViewSite, Viewer, HeavyComponent, ComponentListener {
- private IDAView _view;
- private ViewEventCB _eventCB;
- private Preferences _prefs;
- private Model _model;
- private long _startTime;
- private double _lastTick;
- private long _minFrameTime;
- ErrorAndWarningReceiver _errorRecv = new DefaultErrReceiver();
-
- public synchronized void startModel() throws DXMException {
- try {
- if (this._model == null) {
- throw this.handleError(-2147467259, "No model set", false);
- } else {
- this.ensureViewIsCreated();
- this._view.putWindow(((WComponentPeer)((Component)this).getPeer()).gethwnd());
- this._view.putSite(this);
- this._lastTick = (double)0.0F;
- if (this._model.getImportBase() == null) {
- this._model.setImportBase(this.calculateDocBase());
- }
-
- BvrsToRun var1 = new BvrsToRun(this._view);
- this._model.createModel(var1);
- var1.invalidate();
- ImageBvr var2 = this._model.getImage();
- if (var2 == null) {
- var2 = Statics.emptyImage;
- }
-
- SoundBvr var3 = this._model.getSound();
- if (var3 == null) {
- var3 = Statics.silence;
- }
-
- this._view.StartModel(var2.getCOMPtr(), var3.getCOMPtr(), (double)0.0F);
- this._model.setImage((ImageBvr)null);
- this._model.setSound((SoundBvr)null);
- this._startTime = System.currentTimeMillis();
- this._eventCB = new ViewEventCB(this._view, this, this, this._startTime);
- Preferences var4 = this.getPreferences();
- long var5 = (long)var4.getDouble("Max FPS");
- if (var5 > 0L) {
- this._minFrameTime = 1000L / var5;
- } else {
- this._minFrameTime = 0L;
- }
-
- }
- } catch (ComFailException var8) {
- throw this.handleError(var8, false);
- }
- }
-
- public synchronized void stopModel() throws DXMException {
- try {
- if (this._view != null) {
- this._view.StopModel();
- this._view = null;
- }
-
- this._eventCB = null;
- this._startTime = 0L;
- this._lastTick = (double)0.0F;
- } catch (ComFailException var3) {
- throw this.handleError(var3, false);
- }
- }
-
- public abstract synchronized void showModel();
-
- public void ReportError(int var1, String var2) {
- }
-
- public void componentShown(ComponentEvent var1) {
- this.showModel();
- }
-
- private URL calculateDocBase() {
- boolean var1 = false;
- Container var2 = ((Component)this).getParent();
-
- while(var2 != null && !var1) {
- if (var2 instanceof Applet) {
- var1 = true;
- } else {
- var2 = ((Component)var2).getParent();
- }
- }
-
- URL var3;
- if (var1) {
- Applet var4 = (Applet)var2;
- var3 = var4.getCodeBase();
- } else {
- try {
- String var7 = "file:/" + System.getProperty("user.dir") + "/";
- var7 = var7.replace('\\', '/');
- var3 = new URL(var7);
- } catch (MalformedURLException var6) {
- throw this.handleError(3, ((Throwable)var6).toString(), false);
- }
- }
-
- return var3;
- }
-
- protected synchronized double systemTimeToGlobalTime(long var1) {
- return (double)(var1 - this._startTime) / (double)1000.0F;
- }
-
- public void componentResized(ComponentEvent var1) {
- }
-
- public void componentHidden(ComponentEvent var1) {
- this.hideModel();
- }
-
- protected synchronized ViewEventCB getEventCB() {
- return this._eventCB;
- }
-
- public synchronized double getCurrentTickTime() {
- return this._lastTick;
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- public abstract synchronized void addModel();
-
- public synchronized ErrorAndWarningReceiver getErrorAndWarningReceiver() {
- return this._errorRecv;
- }
-
- protected synchronized long getStartTime() {
- return this._startTime;
- }
-
- public boolean needsHeavyPeer() {
- return true;
- }
-
- public synchronized void removeNotify() {
- this.removeModel();
- super.removeNotify();
- }
-
- public void SetStatusText(String var1) {
- System.out.println(var1);
- }
-
- public abstract synchronized void removeModel();
-
- public abstract synchronized void hideModel();
-
- public synchronized void paint(Graphics var1) {
- if (this._eventCB != null) {
- this._eventCB.RePaint(var1);
- }
-
- }
-
- public synchronized void addNotify() {
- super.addNotify();
- this.addModel();
- }
-
- public synchronized ErrorAndWarningReceiver registerErrorAndWarningReceiver(ErrorAndWarningReceiver var1) {
- ErrorAndWarningReceiver var2 = this._errorRecv;
- this._errorRecv = var1;
- return var2;
- }
-
- public void cleanup() {
- this.stopModel();
- if (this._model != null) {
- this._model.cleanup();
- this._model = null;
- }
-
- this._errorRecv = null;
- this._prefs = null;
- }
-
- public synchronized void tick(double var1) throws DXMException {
- try {
- if (this._view != null) {
- this._lastTick = var1;
- long var3 = System.currentTimeMillis();
- if (this._view.Tick(var1)) {
- this._view.Render();
- }
-
- long var5 = System.currentTimeMillis() - var3;
- if (var5 < this._minFrameTime) {
- try {
- Thread.currentThread();
- Thread.sleep(this._minFrameTime - var5);
- } catch (InterruptedException var8) {
- }
- }
- }
-
- } catch (ComFailException var9) {
- throw this.handleError(var9, true);
- }
- }
-
- public void tick() throws DXMException {
- this.tick(this.getCurrentTime());
- }
-
- public DXMCanvasBase() {
- ((Component)this).addComponentListener(this);
- }
-
- protected synchronized IDAView getView() {
- return this._view;
- }
-
- public synchronized Preferences getPreferences() throws DXMException {
- if (this._prefs == null) {
- try {
- this.ensureViewIsCreated();
- IDAPreferences var1 = this._view.getPreferences();
- this._prefs = new Preferences(var1);
- } catch (ComFailException var3) {
- throw this.handleError(var3, false);
- }
- }
-
- return this._prefs;
- }
-
- public void componentMoved(ComponentEvent var1) {
- }
-
- protected synchronized void ensureViewIsCreated() throws DXMException {
- if (this._view == null) {
- this._view = new DAView();
- }
-
- }
-
- public synchronized void clearModel() {
- this._model = null;
- }
-
- protected DXMException handleError(ComFailException var1, boolean var2) throws DXMException {
- return this.handleError(((ComException)var1).getHResult(), ((Throwable)var1).getMessage(), var2);
- }
-
- protected DXMException handleError(int var1, String var2, boolean var3) throws DXMException {
- if (var3) {
- this._errorRecv.handleTickError(var1, var2, this);
- } else {
- this._errorRecv.handleError(var1, var2, this);
- }
-
- return new DXMException(var1, var2);
- }
-
- public synchronized Model getModel() {
- return this._model;
- }
-
- public synchronized void setModel(Model var1) throws DXMException {
- if (this._model == null) {
- this._model = var1;
- } else {
- throw this.handleError(-2147467259, "setModel: Model already set", false);
- }
- }
-
- public double getCurrentTime() {
- return this.systemTimeToGlobalTime(System.currentTimeMillis());
- }
- }
-